home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / superv22.zip / DUMB.ASM next >
Assembly Source File  |  1987-02-10  |  7KB  |  329 lines

  1.     PAGE    ,132  ; (CTRL-OH)   IBM PC PRINTER CONDENSED MODE
  2.     TITLE    DUMB  - RUDIMENTARY DUMB TERMINAL PROGRAM USING SUPERCOM
  3. CSEG    SEGMENT PARA PUBLIC 'CODE'
  4.     ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG ;ALREADY SET BY DOS LOADER
  5. ;
  6. ;    THIS PROGRAM DEMONSTRATES HOW TO USE A FEW OF THE SUPERCOM 
  7. ;    FEATURES FROM ASSEMBLY LANGUAGE. TERMINATE BY PRESSING ^Z
  8. ;    IT ALSO DEMONSTRATES HOW TO LOAD SUPERCOM FROM WITHIN AN 
  9. ;    APPLICATION AND THEN REMOVE IT AFTERWARD
  10. ;
  11.  
  12.     ORG    100H            ;SKIP TO END OF THE PSP
  13. ENTPT:    JMP    START            ;COM FILE ENTRY ALWAYS AT 100H
  14.  
  15. COPY    DB    8,8,8,'(C) Copyright 1987 Doctor Debug - All rights reserved',26
  16. PMSG    DB    'SUPERCOM not loaded - Postloading...',13,10,'$'
  17. XMSG    DB    13,10,'SUPERCOM removed from memory.',13,10,'$'
  18. PROCEED    DB    'Proceed...',13,10,'$'
  19. ;
  20. ;     NOTHING FANCY HERE, JUST SET THE LINE PARAMETERS IN THESE LOCATIONS
  21. ;
  22. BAUD    DW    1200            ;INIT AT 1200 BAUD
  23. PARITY    DB    3            ;1=ODD, 2=NONE, 3=EVEN
  24. STOP    DB    1            
  25. WORDLEN    DB    7            ;7 OR 8
  26. ECHO    DB    0            ;0 = OFF, 1 = ON
  27. LF    DB    0            ;ADD LF IF 1, NO IF 0
  28. POSTLOAD    DB    0        ;1 if SUPERCOM Postloaded
  29. ;
  30. START    PROC    NEAR
  31. ;
  32. ;    FIRST INITIALIZE THE PORT
  33. ;
  34.     STI
  35.     MOV    BL,0
  36.     MOV    AX,BAUD            ;DETERMINE BAUD RATE
  37.  
  38.     CMP    AX,300            
  39.     JE    B300            ;SET UP FOR 300
  40. ;
  41.     CMP    AX,1200
  42.     JE    B1200            ;SET UP FOR 1200
  43. ;
  44.     CMP    AX,2400
  45.     JE    B2400            ;SET UP FOT 2400
  46. ;
  47.     CMP    AX,4800            
  48.     JE    B4800            ;SET UP FOR 4800
  49. ;
  50. ;    DEFAULT = 9600
  51. ;    
  52. B9600:    MOV    BL,0E0H            ;BL MUST HAVE PROPER CODE
  53.     JMP    I1
  54. ;
  55. B4800:    MOV    BL,0C0H
  56.     JMP    I1
  57. ;
  58. B2400:    MOV    BL,0AH
  59.     JMP    I1
  60. ;
  61. B1200:    MOV    BL,80H
  62.     JMP    I1
  63. ;
  64. B300:    MOV    BL,40H
  65. ;
  66. I1:    MOV    AH,PARITY        ;NOW CHECK PARITY
  67.     MOV    CL,3
  68.     SAL    AH,CL
  69.     OR    BL,AH            ;SET THOSE BITS
  70. ;        
  71.     MOV    AH,STOP            ;HANDLE STOP BITS
  72.     DEC    AH
  73.     MOV    CL,2
  74.     SAL    AH,CL
  75.     OR    BL,AH            ;SET STOP BITS
  76. ;
  77.     MOV    AH,WORDLEN        ;NOW SET WORD LENGTH
  78.     SUB    AH,5
  79.     OR    BL,AH            ;SET THESE BITS
  80. ;
  81. ;    LETS SEE OF SUPERCOM IS LOADED
  82. ;
  83.     MOV    AH,0FH            ;FUNCTION F = HELLO?
  84.     INT    14H            
  85.     CMP    AX,0AAAH        ;RIGHT SIGNATURE?
  86.     JE    GOOD            ;YES, CONTINUE
  87.  
  88. ;    SUPER not loaded, lets do it ourselves
  89.  
  90.     Mov    DX,Offset PMSG
  91.     Mov    AH,9
  92.     Int    21h            ;Prints out message
  93.  
  94.     CALL    LOAD            ;Load supercom
  95.     MOV    POSTLOAD,1        ;SET FLAG
  96.  
  97. GOOD:
  98.     MOV    AL,BL            ;LINE PARAMS IN BL    
  99.     MOV    AH,0CH            ;FUNCTION C = OPEN PORT
  100.     MOV    DX,0
  101.     INT    14H            ;INITS THE COMM PORT
  102. ;
  103.                     ;NOW LOOP, SENDING WHAT'S
  104.                     ;PRINTED AND PRINTING WHAT'S
  105.                     ;SENT...
  106.  
  107.     MOV    DX, OFFSET PROCEED
  108.     MOV    AH,9
  109.     INT    21H            ;PRINT PROCEED MESSAGE
  110.  
  111. LOOP:    MOV    AH,8            ;FN 8 (RECEIVE CHAR)
  112.     MOV    DX,0
  113.     INT    14H            ;SEE IF CHAR EXISTS
  114. ;
  115.     CMP    AL,0            ;NO CHAR?
  116.     JE    L1    
  117.  
  118.     MOV    DL,AL
  119.     MOV    AH,2
  120.     INT    21H            ;PRINT CHAR
  121. ;
  122.     CMP    LF,1            ;ADD LFS?
  123.     JNE    L1
  124. ;
  125.     CMP    AL,0DH            ;CR?
  126.     JNE    L1            ;NO, CONTINUE
  127. ;
  128.     MOV    DL,0AH            ;PRINT LF TOO
  129.     MOV    AH,2
  130.     INT    21H
  131. ;
  132. L1:    MOV    AH,1
  133.     INT    16H            ;CHAR AVAILABLE?
  134.     JZ    LOOP            ;NO, CONTINUE
  135. ;
  136.     MOV    AH,0
  137.     INT    16H            ;get char into al
  138.     CMP    AL,26            ;CTRL-Z?
  139.     JNE    L2            ;no
  140. ;
  141.     CMP    POSTLOAD,1        ;Are we Postloaded?
  142.     Jne    L5
  143.  
  144. ;    We are postloaded, so a Killport is necessary
  145.  
  146.     Mov    DX, Offset XMSG
  147.     Mov    AH,9
  148.     Int    21H            ;Tell what we are doing
  149.  
  150.     Mov    AH,10H            ;Killport Fn #
  151.     Mov    DX,0            ;Port 0
  152.     Int    14h            ;DO IT
  153.     RET                ;AND RETURN
  154. L5:    
  155.     MOV    AH,0DH            ;CLOSE PORT
  156.     MOV    DX,0            
  157.     INT    14H            ;DO IT
  158.     RET                ;EXIT
  159. ;
  160. L2:    MOV    AH,1
  161.     MOV    DX,0
  162.     INT    14H            ;SEND CHARACTER
  163. ;
  164.     CMP    ECHO,1            ;ECHO?
  165.     JNE    LOOP            ;NO, LOOP BACK
  166. ;
  167.     MOV    DL,AL
  168.     MOV    AH,2
  169.     INT    21H            ;ECHO THE CHARACTER
  170. ;
  171.     CMP    AL,0DH            ;IS IT A CARRIAGE RETURN?
  172.     JNE    LOOP            ;NO GO BACK
  173. ;
  174.     MOV    DL,0AH            ;YES PRINT LF WITH IT
  175.     MOV    AH,2
  176.     INT    21H
  177. ;
  178.     JMP    LOOP
  179. ;
  180.  
  181. LOAD    PROC
  182.     JMP    GO
  183.  
  184. ;
  185. ;    This procedure loads Supercom into memory using the DOS EXEC
  186. ;    function (4BH). 
  187. ;
  188. ShellData Label Byte
  189. EnvStr    DW    0            ;Will contain environ string seg
  190. CLin    DD    0            ;Will contain DW ptr to Command line
  191. PFCB1    DD    0            ;DW pointer to unopened FCB
  192. PFCB2    DD    0            ;Ditto
  193.  
  194. Comm    DB    ' /I /X',0        ;Command parameters for SUPER
  195.                     ;Change to suit
  196.  
  197. FCB1    DB    36 dup(0)        ;FCB area 1    
  198.  
  199. FCB2    DB    36 Dup(0)        ;FCB area 2
  200.  
  201. Fname    db    'SUPER.COM',0        ;SUPER filename - put a drive
  202.                     ;and path in if necessary, otherwise
  203.                     ;SUPER.COM is expected to be in
  204.                     ;the current directory
  205.  
  206. SS_Save    DW    0            ;Storage for SS
  207. SP_Save    DW    0            ;Storage for SP
  208.  
  209. GO:
  210.  
  211. ;    1st we must save all registers, as they won't be kept intact
  212. ;    by the call
  213. ;    
  214.     Push    AX
  215.     Push    BX
  216.     Push    CX
  217.     Push    DX
  218.     Push    SI
  219.     Push    DI
  220.     Push    DS
  221.     Push    ES
  222.     Push    BP
  223. ;
  224. ;    In case this is being used in an .EXE file, I will now set
  225. ;    all the segment registers to point to CS. 
  226. ;
  227.     Mov    AX,CS
  228.     Mov    DS,AX
  229.     Mov    ES,AX
  230. ;
  231. ;    Just for fun we will create two unopened FCBs for the exec call
  232. ;
  233.     Mov    AX,2901H        ;Function 29 = Parse filename
  234.     Mov    SI, offset Comm        ;Address of Command Line
  235.     Mov    DI, offset FCB1        ;Where we want the FCB put
  236.     Int    21H            ;Creates the FCB
  237.  
  238.     Mov    DI, offset FCB2        ;Where 2nd FCB should go    
  239.     Int    21h            ;Create it
  240.  
  241. ;    Now we play "fill in the blanks" with the above ShellData
  242. ;    parameter block. We must be sure that the correct segments
  243. ;    and offsets are there
  244.  
  245.     Mov    AX,CS            ;Current segment value
  246.     Mov    Word Ptr[Clin+2],AX    ;Put it here...
  247.     Mov    Word Ptr[PFCB1+2],AX    ;and here...
  248.     Mov    Word Ptr[PFCB2+2],AX    ;and finally here.
  249.     Mov    AX, Offset FCB1        ;Address of FCB we just made
  250.     Mov    Word Ptr[PFCB1],AX    ;Placed into parameter block
  251.     Mov    AX, Offset FCB2        ;Address of other FCB
  252.     Mov    Word Ptr[PFCB2],AX    ;into the block
  253.     Mov    AX, Offset Comm        ;Make sure our command line is here
  254.     Mov    Word Ptr[Clin],AX     
  255.  
  256. ;    We must pass our sub-process an environment string. The segment
  257. ;    of the current string is contained at CS:2C, so lets pass it that
  258.  
  259.     Mov    BX, 2cH
  260.     Mov    AX,Word ptr[BX]        ;get environ seg
  261.     Mov    EnvStr,AX        ;Save it
  262.  
  263. ;    The ShellData parameter block is now all filled in. Now we must 
  264. ;    allocate memory so that there is enough room to load SuperCom
  265. ;    We are reserving 300 paragraphs for our program's use - alter
  266. ;    this to suit. (See the DOS Tech Ref manual if unsure). 0FF
  267. ;    paragraphs is about 16K, so work from that
  268.  
  269.     Mov    AH,4AH            ;4A = Allocate memory
  270.     Mov    BX,300H            ;alocate this many paragraphs
  271.     Int    21H
  272.     Jc    Error            ;Whoops - allocate failed.
  273.                     ;Nothing more we can do
  274.  
  275. ;    All registers, even the stack, will be clobbered by the Exec
  276. ;    Call, so we must save the Stack Segment and Stack Pointer
  277.  
  278.     Mov    SP_Save,SP
  279.     Mov    SS_Save,SS
  280.  
  281. ;    Finally, the address of the filename string must be placed in DS:DX
  282.  
  283.     Mov    DX, offset Fname
  284.  
  285. ;    The address of ShellData must be plaved in BX
  286.  
  287.     Mov    BX, offset ShellData
  288.  
  289. ;    Now set up for the exec call
  290.  
  291.     Mov    AL,0        ;Function 0 = Exec
  292.     Mov    AH,4BH        ;4BH is the DOS function request #
  293.     Int    21H        ;Do the EXEC
  294.     JC    Error        ;Exec failed - error
  295. ;
  296. ;    OK, we are back and the only register we can be sure of is
  297. ;    CS. Lets reload our Stack info
  298. ;
  299.     Mov    SS,CS:SS_Save
  300.     Mov    SP,CS:SP_Save
  301.     Clc                ;Clear carry means successful load
  302. ;
  303. ;    Now we can pop off our original registers
  304. ;
  305.  
  306. Pop_Regs:
  307.     Pop    BP
  308.     Pop    ES
  309.     Pop    DS
  310.     Pop    DI
  311.     Pop    SI
  312.     Pop    DX
  313.     Pop    CX
  314.     Pop    BX
  315.     Pop    AX
  316.  
  317.     Ret
  318.      
  319. Error:    Stc                ;Set carry means load failed
  320.                     ;System may be unhealthy
  321.     Jmp    Pop_Regs
  322.  
  323.     RET                ;NEAR RETURN TO DOS
  324. LOAD    ENDP
  325.  
  326. START    ENDP
  327. CSEG    ENDS
  328.     END    ENTPT
  329.